package com.cictec.middleware.core.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cictec.middleware.commons.cache.ecache.EHCacheUtils;
import com.cictec.middleware.commons.utils.ZoneUtils;
import com.cictec.middleware.core.entity.StandbyZone;
import com.cictec.middleware.core.mapper.BusLineStandbyMapper;

/**
 * 线路信息-待发区service
 * @author ql
 *
 */
@Service
public class BusLineStandbyService {

	public static Logger logger = LoggerFactory.getLogger(BusLineStandbyService.class);

	@Autowired
	private BusLineStandbyMapper busLineStandbyMapper;

	private static String LINE_STANDBY_CACHE = "bus-line-standby"; 		  			// 线路待发区

	
	/**
	 * 刷新线路待发区缓存
	 * @param lineUuid
	 */
	public void reloadLineStandyInfo(String lineUuid){
		
		List<StandbyZone> lss = selectStandbyZones(lineUuid);
		EHCacheUtils.setValue(LINE_STANDBY_CACHE, lineUuid, lss);
	}
	
	/**
	 * 获取线路上车辆待发区【缓存中取，没有的时候取数据库】
	 * 
	 * @param lineUuid
	 * @return
	 */
	public List<StandbyZone> getStandbyZones(String lineUuid) {

		List<StandbyZone> list = EHCacheUtils.getValue(LINE_STANDBY_CACHE, lineUuid);

		if (list != null) {
			return list;
		}

		list = selectStandbyZones(lineUuid);
		EHCacheUtils.setValue(LINE_STANDBY_CACHE, lineUuid, list);

		return list;
	}
	
	/**
	 * 获取线路上车辆待发区【数据库】
	 * 
	 * @param lineUuid
	 * @return
	 */
	public List<StandbyZone> selectStandbyZones(String lineUuid) {
		List<StandbyZone> list = busLineStandbyMapper.selectStandbyZones(lineUuid);
		return list;
	}
	
	
	
	
}
